package yang.java8.newTimeApi;

import java.time.DayOfWeek;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.util.concurrent.TimeUnit;

public class TimeLine {

	public static void main(String[] args) throws InterruptedException {
	}
	
	public static void InstantAndDuration() throws InterruptedException {
		Instant instant = Instant.now(); // 当前时间点
		instant = Instant.MAX; //10_0000_0000年的12月31日
		instant = Instant.MIN;//10亿年前
		Instant start = Instant.now();
		TimeUnit.SECONDS.sleep(1);
		Instant end = Instant.now();
		Duration timeElapsed = Duration.between(start, end);//计算两个瞬时点之间的时间量
		System.out.println(timeElapsed.toDays() + "**" + timeElapsed.toMinutes() +
				"**" + timeElapsed.toMillis() + "**" + timeElapsed.toNanos());
	}
	
	public static void LocalDate() {
		LocalDate today = LocalDate.now(); // 今天的日期
		LocalDate alonzosBirthday = LocalDate.of(1903, 6, 14); // 日期和月份是从1开始的
		alonzosBirthday = LocalDate.of(1903, Month.JUNE, 14);
	}
	
	public static void Adjusters() {
		LocalDate firstTuesday = LocalDate.of(1900, 1, 1).with(TemporalAdjusters.nextOrSame(DayOfWeek.THURSDAY));// 时间的下一个星期二
		LocalDate monthSecondSunday = LocalDate.now().with(TemporalAdjusters.dayOfWeekInMonth(2, DayOfWeek.SUNDAY)); // 当前月第几个周日
	}
	
	public static void LocalTimeApi() {
		LocalTime rightNow = LocalTime.now();
		LocalTime bedTime = LocalTime.of(22, 30);
		LocalTime wakeup = bedTime.plusHours(8);
		LocalDateTime dateTime = LocalDateTime.now();
	}
	
	public static void zoneDateTime() {
		ZonedDateTime apollolllaunch = ZonedDateTime.of(1969, 7, 16, 9, 32, 0, 0, ZoneId.of("America/New_York"));
		Instant instant = apollolllaunch.toInstant();
		ZonedDateTime utc = instant.atZone(ZoneId.of("UTC"));
	}
	
	public static void format() {
		ZonedDateTime time = ZonedDateTime.now();
		String formatted = DateTimeFormatter.ISO_DATE_TIME.format(time);
		System.out.println(formatted);
	}

}
